package com.wss.juc;

import java.util.concurrent.LinkedBlockingQueue;

public class yy {
    private static final LinkedBlockingQueue<Integer> queue = new LinkedBlockingQueue<>(3);

    public static void main(String[] args) throws InterruptedException {
        Thread threadC = new Thread(() -> {
            try {
                System.out.println("C");
                queue.put(1);
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
            }
        });

        Thread threadB = new Thread(() -> {
            try {
                queue.take();
                System.out.println("B");
                queue.put(2);
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
            }
        });

        Thread threadA = new Thread(() -> {
            try {
                queue.take();
                System.out.println("A");
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
            }
        });


        threadA.start();
        threadB.start();
        threadC.start();

        threadA.join();
        threadB.join();
        threadC.join();
    }
}